package com.sky.task;

import com.sky.entity.Orders;
import com.sky.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class TimeoutTask {
    @Autowired
    private OrderMapper orderMapper;
    @Scheduled(cron = "0 * * * * ?")
    public void orderTimeout() {
        log.info("订单超时检查");
        LocalDateTime time = LocalDateTime.now().plusMinutes(-15);
        orderMapper.updateWrongStatus(Orders.PENDING_PAYMENT,Orders.CANCELLED,time);
    }
    @Scheduled(cron = "0 0 1 * * ?")
    public void processDeliveryOrder() {
        log.info("处理处于待派送状态的订单");
        LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
        orderMapper.updateWrongStatus(Orders.DELIVERY_IN_PROGRESS,Orders.COMPLETED,time);
    }
}
